﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CSharpDesign.DAL;

namespace CSharpDesign
{
    public partial class SearchShangPinList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Title = " 水果商店";
            if (!IsPostBack)
            {
                BindDataSource();
            }
        }
        private void BindDataSource()
        {
            int CurPage;
            string commodityName = Request.QueryString["SPName"].ToString();
            string categoryName = Request.QueryString["ShangPinFenLeiName"].ToString();

            PagedDataSource objPds = new PagedDataSource();
            objPds.DataSource = SearchShangPinBLL.SearchCommodityList(commodityName, categoryName).Tables[0].DefaultView;

            objPds.AllowPaging = true;
            objPds.PageSize = 16;

            if (Request.QueryString["Page"] != null)
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            else
                CurPage = 1;

            objPds.CurrentPageIndex = CurPage - 1;
            lblCurrentPage.Text = CurPage.ToString();
            lblSumPage.Text = objPds.PageCount.ToString();

            if (!objPds.IsFirstPage)
            {
                hyfirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + 1 + "&SPName=" + Request.QueryString["SPName"].ToString() + "&ShangPinFenLeiName=" + Request.QueryString["ShangPinFenLeiName"].ToString();
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + "&SPName=" + Request.QueryString["SPName"].ToString() + "&ShangPinFenLeiName=" + Request.QueryString["ShangPinFenLeiName"].ToString();
            }
            if (!objPds.IsLastPage)
            {
                hylastpage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + objPds.PageCount + "&SPName=" + Request.QueryString["SPName"].ToString() + "&ShangPinFenLeiName=" + Request.QueryString["ShangPinFenLeiName"].ToString();
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + "&SPName=" + Request.QueryString["SPName"].ToString() + "&ShangPinFenLeiName=" + Request.QueryString["ShangPinFenLeiName"].ToString();
            }

            DataList1.DataSource = objPds;
            DataList1.DataBind();
        }
    }
}